package com.rongshu.view.userInfo.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.utils.Common;
import com.rongshu.utils.Constant;
import com.rongshu.utils.UserInfoUtils;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetBean;
import com.rongshu.view.userInfo.iview.DirectMessageView;
import com.rongshu.view.userInfo.entity.DirectMessage;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;

public class DirectMessagePresenter extends BasePresenter<DirectMessageView> {

    public DirectMessagePresenter(Context context) {
        super(context);
    }

    /**
     * 我的私信
     */
    public void getMyPrivateMessage(int user_id, int pageIndex, int pageSize, String sign) {
        RetorfitService.getMyPrivateMessage(user_id, pageIndex, pageSize, sign)
                .compose(getView().<DirectMessage>bindToLife())
                .subscribe(new Subscriber<DirectMessage>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(DirectMessage directMessage) {
                        if (getView() != null) {
                            getView().onDirectMessageList(directMessage);
                        }
                    }
                });
    }

    /**
     * 删除私信
     */
    public void getDeletePrivatechat(int send_userid, int receive_userid, String sign) {
        RetorfitService.getDeletePrivatechat(send_userid, receive_userid, sign)
                .compose(getView().<INetBean>bindToLife())
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {

                    }
                });
    }

    /**
     * 点击私信/@我的/文章评论消息，标记全部已读
     */
    public void GetMsgAllRead() {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", UserInfoUtils.getUserId());
        map.put("type", Constant.PRATIVE_LATTER);
        RetorfitService.GetMsgAllRead(UserInfoUtils.getUserId(), Constant.PRATIVE_LATTER, Common.encryptionSign(map))
                .compose(getView().<INetBean>bindToLife())
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {

                    }
                });
    }
}
